#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsScene>
#include <QgraphicsView>
#include <QTextStream>
#include <player.h>
namespace Ui {
    class MainWindow;
}

player * trick_winner(card * trick[], int num_cards_played);

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    player * players[4];
    void redraw();

    //init
    void doMenu();
    void doDeck();
    void doPlayers();
    void doScoreboard();
    void doTrickbox();
    bool isWinner();
    void doDeal();
    void doBid();
    int  doUiBid(int defaultbid=0);

    //playing
    void doPlay();
    card * doUiPlay();
    void doTrick();
    void update_bid_tracking();
    void update_scoreboard(player *, player *);
    void clean_up(card **);

    player * leader;
    card * trick[4];
    bool isSpadesBroken;


public slots:
    void doNewGame();

private:
    //   Ui::MainWindow *ui;
    enum STATES{ DEALING=1, BIDDING, PLAYING, SCORING } state;
    QGraphicsScene *scene;
    QGraphicsView *view;

    QGraphicsItemGroup * scoreboard;
    QGraphicsSimpleTextItem * NS_score;
    QGraphicsSimpleTextItem * EW_score;
    QGraphicsSimpleTextItem * NS_bid;
    QGraphicsSimpleTextItem * EW_bid;

    QGraphicsItemGroup * trickbox;
    QGraphicsRectItem * S_trickbox;
    QGraphicsRectItem * W_trickbox;
    QGraphicsRectItem * N_trickbox;
    QGraphicsRectItem * E_trickbox;

    QList<card *> deck;
    QList<card *> discard;
    QTextStream out;

    //RULES
    const int WINNING_SCORE;
    const int LOSING_SCORE;
    const int NUM_HANDS; //unused
    const int NIL_POINTS;
    const int BAG_POINTS;
    const int MAX_BAGS;
    const int BAG_PENALTY;
    const int BOARD;
    const bool ALLOW_LYING;
    const bool SPADES_MUST_BE_BROKEN;
    const bool ALLOW_SMALL_BLINDS;
    const bool ALLOW_BLIND_NIL; 
    const bool BIG_BONUS;
    const int  BONUS_POINTS;
    const int  TRICKS_FOR_BONUS;


protected:
    void resizeEvent(QResizeEvent *event);
};

#endif // MAINWINDOW_H
